package com.youku.plugins.commonui.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.plugins.commonui.CommonUIEvent;
   import com.youku.events.PlayerControlEvent;
   import com.youku.events.ConductorEvent;
   import com.youku.events.PluginEvent;
   import com.youku.conductor.ConductorState;
   
   public class ReadyToPlayScreenV4Mediator extends Object
   {
      
      public function ReadyToPlayScreenV4Mediator(param1:MovieClip, param2:IPlayerProxy) {
         super();
         this._mainMC = param1;
         this._playerProxy = param2;
         this._screen = new ReadyToPlayScreenV4();
         this.init();
      }
      
      private var _mainMC:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _screen:ReadyToPlayScreenV4;
      
      private function init() : void {
         this._screen.addEventListener(CommonUIEvent.READY_TO_PLAY_CLICK,this.onScreenEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.FULLSCREEN_CHANGED,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_SIZE_CHANGED,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.SHOW_READY_TO_PLAY_SCREEN,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(ConductorEvent.STATE_CHANGED,this.onStateChanged);
      }
      
      private function onScreenEvent(param1:CommonUIEvent) : void {
         switch(param1.type)
         {
            case CommonUIEvent.READY_TO_PLAY_CLICK:
               this._playerProxy.dispatchEvent(new PluginEvent(PluginEvent.READY_TO_PLAY_CLICK));
               break;
         }
      }
      
      private function onPlayerControlEvent(param1:PlayerControlEvent) : void {
         var _loc2_:* = NaN;
         var _loc3_:* = NaN;
         var _loc4_:* = false;
         var _loc5_:* = NaN;
         var _loc6_:String = null;
         switch(param1.type)
         {
            case PlayerControlEvent.FULLSCREEN_CHANGED:
            case PlayerControlEvent.PLAYER_SIZE_CHANGED:
               _loc2_ = param1.data.width;
               _loc3_ = param1.data.height;
               _loc4_ = param1.data.fullscreen;
               _loc5_ = param1.data.cheight;
               if(_loc4_)
               {
                  this._screen.setSize(_loc2_,_loc3_);
               }
               else
               {
                  this._screen.setSize(_loc2_,_loc3_ - _loc5_);
               }
               break;
            case PlayerControlEvent.SHOW_READY_TO_PLAY_SCREEN:
               _loc6_ = this._playerProxy.playerData.videoLogoURL;
               if(!(this._playerProxy.rootGetData.rootImglogo == null) && !(this._playerProxy.rootGetData.rootImglogo == ""))
               {
                  _loc6_ = this._playerProxy.rootGetData.rootImglogo;
               }
               if(this._mainMC.contains(this._screen))
               {
                  this._mainMC.removeChild(this._screen);
               }
               this._mainMC.addChild(this._screen);
               this._screen.setURL(_loc6_);
               this._screen.visible = true;
               this._screen.show(true);
               break;
         }
      }
      
      private function onStateChanged(param1:ConductorEvent) : void {
         var _loc2_:String = param1.data as String;
         switch(_loc2_)
         {
            case ConductorState.VIDEO:
               if(this._mainMC.contains(this._screen))
               {
                  this._mainMC.removeChild(this._screen);
               }
               this._screen.show(false);
               break;
         }
      }
   }
}
